
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )

/*---------------------------------------------------------
   Name: Initialize
---------------------------------------------------------*/
function ENT:Initialize()

	self:PhysicsInit( SOLID_VPHYSICS )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS ) 
	self.StartSpray = Sound("buttons/lever5.wav")
	
	local phys = self:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
		phys:EnableDrag(true)
		phys:EnableCollisions(true)
		phys:SetMass(100)
	end
	
end

function ENT:Explode()
	if not self.Asploded then
		self.Asploded = true
		local effectdata = EffectData()
		effectdata:SetOrigin(self:GetPos())
		util.Effect("molotov_explosion", effectdata)

		self:ExplosionDamage(self.Pwner,self:GetPos(),50,280)
		self:EmitSound(ChooseRandom(GameSounds.Ricochet),80,math.random(90,110))
	
		self:Remove()
	end
end

function ENT:SetPwner(ply)
	self.Pwner = ply
end

/*---------------------------------------------------------
   Name: Think
---------------------------------------------------------*/
function ENT:Think()
	if not self.Spray then
		self.Spray = true
		local effectdata = EffectData()
		effectdata:SetEntity(self)
		util.Effect("propane_spray", effectdata)
	end
	if self.Exploded then
		self:Explode() 
	end
end 
 
 /*---------------------------------------------------------
   Name: takedamage
---------------------------------------------------------*/
function ENT:OnTakeDamage( dmginfo )	
	if self.Exploded then return end
	self.Exploded = true
end


/*---------------------------------------------------------
   Name: PhysicsCollide
---------------------------------------------------------*/
function ENT:PhysicsCollide( data, physobj )
	if (data.Speed > 40 && data.DeltaTime > 0.2 ) then
		self:EmitSound(ChooseRandom(GameSounds.PropaneHit),80,math.random(90,110))
		if not self.Emitted then
			self.Emitted = true
			self:EmitSound(self.StartSpray,80,math.random(90,110))
		end
	end
end